package com.ijunfu.study.jdk.jdk8.date;

import java.time.Duration;
import java.time.LocalTime;

/**
 * @Title : Duration 两个时间之差计算示例
 * @Remarks:
 * @Author : Weizhiguo
 * @Version: 1.0.0
 * @Date : 2022-05-01
 */
public class DurationDemo {

    public static void main(String[] args) {
        LocalTime now = LocalTime.now();    // 09:20:32

        LocalTime time = LocalTime.of(12, 13, 14);

        // 计算时间之差，后面减前面
        Duration duration = Duration.between(now, time);
        System.out.println(duration.toDays());              // 相差 天
        System.out.println(duration.toHours());             // 相差 小时
        System.out.println(duration.toMinutes());           // 相差 分钟
        System.out.println(duration.toMillis());            // 相差 毫秒
    }

}
